package com.example.administrator.xinyutg.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by Administrator on 2015/9/26.
 */
public class HttpUtil {
    public static String getJSON(String path){
        String result="";
        try {
            URL url=new URL(path);
            try {
                HttpURLConnection con= (HttpURLConnection) url.openConnection();
                if (con.getResponseCode()==200){
                    BufferedReader br=new BufferedReader(new InputStreamReader(con.getInputStream()));
                    String temp="";
                    while ((temp=br.readLine())!=null){
                        result+=temp;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

        return result;
    }
}
